package class03;

public class Code01_RecursiveTraversalBT {

    static class Node {
        int value;
        Node left;
        Node right;

        Node(int value) {
            this.value = value;
        }
    }

    // 先序
    static void pre(Node node) {
        if (null == node) {
            return;
        }
        System.out.println(node.value);
        pre(node.left);
        pre(node.right);
    }

    // 中序
    static void in(Node node) {
        if (null == node) {
            return;
        }
        in(node.left);
        System.out.println(node.value);
        in(node.right);
    }

    //后序
    static void pos(Node node) {
        if (null == node) {
            return;
        }
        pos(node.left);
        pos(node.right);
        System.out.println(node.value);
    }

    // 以上抽象出f
    static void f(Node node) {
        //  先序
        f(node.left);
        // 中序
        f(node.right);
        // 后序
    }

    public static void main(String[] args) {
        Node head = new Node(1);
        head.left = new Node(2);
        head.right = new Node(3);
        head.left.left = new Node(4);
        head.left.right = new Node(5);
        head.right.left = new Node(6);
        head.right.right = new Node(7);

        pre(head);
        System.out.println("========");
        in(head);
        System.out.println("========");
        pos(head);
        System.out.println("========");

    }
}
